package com.geek.bams.entity;

import com.geek.bams.exception.LoanException;

/**
 * @Desc TODO
 * @Author chenmin
 * @Date 2025/10/16
 */
public class LoanSavingAccount extends SavingAccount implements Loanable {
    private static final long serialVersionUID = 1L;

    private long loanAmount;

    public LoanSavingAccount() {
    }

    public LoanSavingAccount(Long id, String name, String password, String personId, String email, double balance, long loanAmount) {
        super(id, name, password, personId, email, balance);
        this.loanAmount = loanAmount;
    }

    //贷款
    @Override
    public Account requestLoan(double money) throws LoanException {
        if(money>0.0){
            loanAmount+=money;
            this.setBalance(this.getBalance() + money);
            return this;
        }
        /*System.out.println("贷款操作金额不能小于0.0");
        return this;*/
        throw new LoanException("贷款操作金额不能小于0.0!");
    }

    //还款
    @Override
    public Account payLoan(double money) throws LoanException {
        if(money>0.0){
            if(money<=loanAmount){
                if(this.getBalance()>=money){
                    loanAmount-=money;
                    this.setBalance(this.getBalance() - money);
                }else{
                    //System.out.println("还款余额不足！");
                    throw new LoanException("您的账户还款余额不足!");
                }
            }else{
                //System.out.println("还多了！");
                throw new LoanException("还多了!");
            }
            return this;
        }
        /*System.out.println("还款操作金额不能小于0.0");
        return this;*/
        throw new LoanException("还款操作金额不能小于0.0!");
    }

    /**
     * 获取
     * @return loanAmount
     */
    public long getLoanAmount() {
        return loanAmount;
    }

    /**
     * 设置
     * @param loanAmount
     */
    public void setLoanAmount(long loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public String toString() {
        return "LoanSavingAccount{" +
                "loanAmount=" + loanAmount +
                "} " + super.toString();
    }
}
